import { EventDispatcher } from "oasis-engine";

export enum RoleState {
  Idle = "idle",
  Jumping = "jumping",
  Dead = "dead",
}

export enum StateChangeEvent {
  Idle = "idle",
  Jumping = "jumping",
  Dead = "dead",
}

export class StateMachine extends EventDispatcher {
  private static _ins: StateMachine;
  public static getInstance() {
    return this._ins;
  }

  private _currentState: RoleState = RoleState.Idle;

  public get currentState() {
    return this._currentState;
  }

  private constructor() {
    super();
  }

  public changeState(state: RoleState) {
    if (this._currentState === state) return;

    this._currentState = state;
    this.dispatch(state);
  }
}
